package com.fenghongzhang.day004;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        CheckBox checkBox = findViewById(R.id.qiu);
        CheckBox checkBox2 = findViewById(R.id.qiu2);

        MyListener myListener = new MyListener();
        checkBox2.setOnCheckedChangeListener(myListener);
        checkBox.setOnCheckedChangeListener(myListener);
    }


    //内部类实现监听
    class MyListener implements CompoundButton.OnCheckedChangeListener{

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
                Toast.makeText(Main2Activity.this, "选中", Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(Main2Activity.this, "取消了", Toast.LENGTH_SHORT).show();
            }
        }
    }

}
